package com.xujiakai.car.maintain.userinterface.views;

import com.xujiakai.car.maintain.application.service.impl.BaseDataManageService;
import com.xujiakai.car.maintain.domain.dto.CustomerDTO;
import com.xujiakai.car.maintain.domain.dto.VehicleDTO;
import com.xujiakai.car.maintain.infrastructure.utils.StringUtils;

import java.text.SimpleDateFormat;

/**
 * 用户管理的视图
 *
 * @author desenyang tz
 *
 */
public class CustomerView {
	private String customerid;
	private String customername;
	private String contactinfo;
	private String contactadd;
	private String vehicleid;
	private String platenum;
	private String carmodel;
	private String inspectiondate;
	private String milage;
	private String vehflag;



	public String getCustomerid() {
		return customerid;
	}

	public void setCustomerid(String customerid) {
		this.customerid = customerid;
	}

	public String getCustomername() {
		return customername;
	}

	public void setCustomername(String customername) {
		this.customername = customername;
	}

	public String getContactinfo() {
		return contactinfo;
	}

	public void setContactinfo(String contactinfo) {
		this.contactinfo = contactinfo;
	}

	public String getContactadd() {
		return contactadd;
	}

	public void setContactadd(String contactadd) {
		this.contactadd = contactadd;
	}

	public String getVehicleid() {
		return vehicleid;
	}

	public void setVehicleid(String vehicleid) {
		this.vehicleid = vehicleid;
	}

	public String getPlatenum() {
		return platenum;
	}

	public void setPlatenum(String platenum) {
		this.platenum = platenum;
	}

	public String getCarmodel() {
		return carmodel;
	}

	public void setCarmodel(String carmodel) {
		this.carmodel = carmodel;
	}

	public String getInspectiondate() {
		return inspectiondate;
	}

	public void setInspectiondate(String inspectiondate) {
		this.inspectiondate = inspectiondate;
	}

	public String getMilage() {
		return milage;
	}

	public void setMilage(String milage) {
		this.milage = milage;
	}

	public String getVehflag() {
		return vehflag;
	}

	public void setVehflag(String vehflag) {
		this.vehflag = vehflag;
	}


	public boolean modifyCustomer(){
		boolean flag = true;
		int i = 0;
		try {
			com.xujiakai.car.maintain.domain.entity.Customer customerDTO = new com.xujiakai.car.maintain.domain.entity.Customer();
			CustomerDTO customer = customerDTO.getCustomer(customerid);
			if (customer != null) {
				customer.setContactadd(contactadd);
				customer.setContactinfo(contactinfo);
				customer.setNumbering(customername);
				// 更新用户的信息
				customerDTO.updateByPrimaryKeySelective(customer);
				++i;
			}
			com.xujiakai.car.maintain.domain.entity.Vehicle vehicleDTO = new com.xujiakai.car.maintain.domain.entity.Vehicle();
			VehicleDTO vehicle = vehicleDTO.createVehicle(vehicleid);
			if (vehicle != null) {
				vehicle.setPlatenum(platenum);
				vehicle.setInspectiondate(new SimpleDateFormat("yyyy-MM-dd").parse(inspectiondate));
				vehicle.setMilage(StringUtils.getDoubleValue(milage, -1d));
				vehicle.setVehflag(vehflag);
				// 更新车辆信息
				vehicleDTO.updateByPrimaryKeySelective(vehicle);
				++i;
			}
		} catch (Exception e) {
			BaseDataManageService.logger.info("修改用户信息失败!");
		}
		return (i == 2);
	}

}
